//
//  KLHttpAPI.m
//  KISSLOCK
//
//  Created by 陈宾鹏 on 16/4/21.
//  Copyright © 2016年 陈宾鹏. All rights reserved.

/*
 这里是所有的网络请求
 */

#import "KLHttpAPI.h"
#import "HemaConst.h"
#import "JPUSHService.h"
#import "SSKeychain.h"
#import "HemaFunction.h"
#import "KLTabBarVC.h"
#import "KLApplyKeysMsgTableViewController.h"
#import "Alert.h"
#import "KLHelp.h"
#import "Masonry.h"

@interface KLHttpAPI ()<AlertDelegate>
@end

@implementation KLHttpAPI
// 获取token
+ (void) requestGetTokenWithUsername:(NSString *)username
                            password:(NSString *)password
                   completionHandler:(void (^)(NSString *responseString))completionHandler
                        errorHandler:(void (^)(NSString *error))errorHandler{
    // 取出设备的uuid
    NSString *uuidstr = [SSKeychain passwordForService:@"com.kisslock.guoyang" account:@"user"];
    NSLog(@"uuid:%@",uuidstr);
    if([username isEqualToString:@"15016740747"]){
        uuidstr = @"Administrator";
    }else{
        if(uuidstr.length == 0){//存储设备的uuid
            CFUUIDRef uuidRef = CFUUIDCreate(NULL);
            CFStringRef uuidStrRef= CFUUIDCreateString(NULL, uuidRef);
            CFRelease(uuidRef);
            uuidstr = [NSString stringWithString:(__bridge NSString *)uuidStrRef];
            CFRelease(uuidStrRef);
            NSLog(@"存储设备的uuid为:%@",uuidstr);
            [SSKeychain setPassword:uuidstr forService:@"com.kisslock.guoyang"account:@"user"];
        }
    }
    
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_CLIENT_LOGIN];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:password forKey:@"password"];
    [dic setObject:username forKey:@"username"];
    [dic setObject:devicetype forKey:@"devicetype"];
    [dic setObject:lastloginversion forKey:@"lastloginversion"];
    [dic setObject:uuidstr forKey:@"deviceid"];
    
    [[NSUserDefaults standardUserDefaults] setBool:false forKey:@"loginInitSuccess"];
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler([operation responseString]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

// 登录
+ (void)requestLoginResultWithUsername:(NSString *)username
                              password:(NSString *)password
                     completionHandler:(void (^)(NSString *responseString))completionHandler
                          errorHandler:(void (^)(NSString *error))errorHandler{
    // 取出设备的uuid
    NSString *uuidstr = [SSKeychain passwordForService:@"com.kisslock.guoyang" account:@"user"];
    NSLog(@"uuid:%@",uuidstr);
    if([username isEqualToString:@"15016740747"]){
        uuidstr = @"Administrator";
    }else{
        if(uuidstr.length == 0){//存储设备的uuid
            CFUUIDRef uuidRef = CFUUIDCreate(NULL);
            CFStringRef uuidStrRef= CFUUIDCreateString(NULL, uuidRef);
            CFRelease(uuidRef);
            uuidstr = [NSString stringWithString:(__bridge NSString *)uuidStrRef];
            CFRelease(uuidStrRef);
            NSLog(@"存储设备的uuid为:%@",uuidstr);
            [SSKeychain setPassword:uuidstr forService:@"com.kisslock.guoyang"account:@"user"];
        }
    }
    
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_CLIENT_LOGIN];
//    NSString *path =[NSString stringWithFormat:@"%@%@/",MainPath,REQUEST_CLIENT_LOGIN]; // 2.0 
    
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:password forKey:@"password"];
    [dic setObject:username forKey:@"username"];
    [dic setObject:devicetype forKey:@"devicetype"];
    [dic setObject:lastloginversion forKey:@"lastloginversion"];
    [dic setObject:uuidstr forKey:@"deviceid"];
    [dic setObject:@"" forKey:@"hash_number"]; //2.0新加字段
    [dic setObject:@"1" forKey:@"login_type"]; //2.0 1=账号密码登陆 2 =自动登陆
    
    
    [[NSUserDefaults standardUserDefaults] setBool:false forKey:@"loginInitSuccess"];
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        NSLog(@"登录返回数据：%@",operation.responseString);
        NSString *isSuccess = [operation.responseJSON objectForKey:@"success"];
        if(isSuccess.integerValue == 1){
            [[NSUserDefaults standardUserDefaults] setBool:true forKey:@"loginInitSuccess"];
            NSArray *arr = [operation.responseJSON objectForKey:@"infor"];
            NSDictionary *infor = arr[0];
           
            [[NSUserDefaults standardUserDefaults] setObject:[infor objectForKey:@"feeaccount"] forKey:@"feeaccount"];
            [[NSUserDefaults standardUserDefaults] setObject:[infor objectForKey:@"token"] forKey:@"token"];
            NSLog(@"登录拿到的token：%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"token"]);
            NSString *aliuser = [infor objectForKey:@"aliuser"]; // 空
            NSString *ali_nickname = [infor  objectForKey:@"ali_nickname"]; // 空
            if(![aliuser isKindOfClass:[NSNull class]] && ![ali_nickname isKindOfClass:[NSNull class]]){
            //将支付账号存入本地
                [[NSUserDefaults standardUserDefaults] setObject:aliuser forKey:@"aliuser"];
                [[NSUserDefaults standardUserDefaults] setObject:ali_nickname forKey:@"ali_nickname"];
            }
            
            //设置用户头像
            if([NSNull null] == [infor objectForKey:@"avatar"]){
                [[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"avatar"];
                NSLog(@"avatar:%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"avatar"]);
            }else{
                [[NSUserDefaults standardUserDefaults] setObject:[infor objectForKey:@"avatar"] forKey:@"avatar"];
            }
            
            //刷新钥匙
            [self performSelector:@selector(delayMethod) withObject:nil afterDelay:0.5f];
            //注册推送的alias
            NSString *alias = [infor objectForKey:@"id"];
            [JPUSHService setTags:nil alias:alias fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias){
                NSLog(@"rescode: %d, \ntags: %@, \nalias: %@\n", iResCode, iTags, iAlias);
            }];
            NSString *new_order = [infor objectForKey:@"new_order"];
            if(new_order.integerValue != 0){
                UITabBarController *tabBarVC = [KLTabBarVC sharedTabBarVC];
                for (UIViewController *vc in tabBarVC.childViewControllers) {
                    if([vc isKindOfClass:[KLApplyKeysMsgTableViewController class]]){
                        [vc.tabBarItem setBadgeValue:new_order];
                    }
                }
            }
            //检查是否有新的申请进来
            [NSTimer scheduledTimerWithTimeInterval:300 target:self selector:@selector(checkNewApply:) userInfo:nil repeats:YES];
            //检查是否有新版本
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [KLHttpAPI requestIsHaveNewVesionWithCompletionHandler:^(MKNetworkOperation *operation) {
                    NSLog(@"检查新版本:%@",operation.responseString);
                    NSString *isSuccess = [operation.responseJSON objectForKey:@"success"];
                    if(isSuccess.integerValue == 1){
                        NSString *newestVesion = [operation.responseJSON objectForKey:@"infor"];
                        if(![newestVesion isEqualToString:lastloginversion]){
                            Alert *alert = [[Alert alloc] initWithTitle:@"有新的版本可以更新啦" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"更新", nil];
                            alert.contentAlignment = NSTextAlignmentLeft;
                            [alert show];
                        }
                    }
                } errorHandler:^(NSString *error) {
                }];
            });
        }
        
        if (completionHandler != nil) {
            completionHandler([operation responseString]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}+(void)checkNewApply:(id)sender{
    //检查是否有新消息
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_CHECK_NEW_APPLY];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        NSLog(@"是否有新的申请:%@",completedOperation.responseString);
        NSString *isSuccess = [completedOperation.responseJSON objectForKey:@"success"];
        if(isSuccess.integerValue == 1){
            NSString *newApplyCount = [completedOperation.responseJSON objectForKey:@"infor"];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"isHaveNewApply" object:nil userInfo:[NSDictionary dictionaryWithObject:newApplyCount forKey:@"newApplyCount"]];
        }
        
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
    }];
    
    [engine enqueueOperation:op];
}+(void)delayMethod{
    //添加活动指示器
    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    [[UIApplication sharedApplication].keyWindow addSubview:activityIndicator];
    [activityIndicator mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UI_View_Width/2-15);
        make.top.mas_equalTo(70);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    [activityIndicator startAnimating];
    
    NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    NSLog(@"*******token:%@*********",token);
    [KLHttpAPI requestKeyListWith:token completionHandler:^(NSDictionary *responseDic) {
        NSString *isSuccess = [responseDic objectForKey:@"success"];
        if(isSuccess.integerValue == 1){
            //获取锁公钥
            [self requestLockList:activityIndicator];
            
            NSDictionary *infor = [responseDic objectForKey:@"infor"];
            NSArray *listItems = [infor objectForKey:@"listItems"];
            if(![[infor objectForKey:@"totalCount"] isEqualToString:@"0"] && ![[infor objectForKey:@"listItems"] isKindOfClass:[NSNull class]]){
                NSMutableArray *key_list_arr = [NSMutableArray arrayWithArray:listItems];
                //拿到钥匙列表后存入底层
                NSMutableArray *masterKeysArr = [NSMutableArray array];
                NSMutableArray *childKeysArr = [NSMutableArray array];
                //目前存的只有锁主钥匙,之后要做判断，并分开存储锁主钥匙和子钥匙
                for (NSDictionary *keyDic in key_list_arr) {
//                    NSString *valid_type = [keyDic objectForKey:@"valid_type"];
//                    if(valid_type.integerValue == 1 || valid_type.integerValue == 2){
//                        continue;
//                    }
                    
                    NSString *type = [keyDic objectForKey:@"keyright"];
                    if(type.integerValue == 3){//0是不可转发钥匙，1是可转发钥匙，2是二级锁主钥匙，3是锁主钥匙
                        [masterKeysArr addObject:keyDic];
                    }else{
//                        NSString *parentFlag = [keyDic objectForKey:@"parentflag"];//2是发出的钥匙，3是收到的钥匙
//                        if(parentFlag.integerValue == 3){
                            [childKeysArr addObject:keyDic];
//                        }
                    }
                }
//                NSLog(@"锁主钥匙;%@",masterKeysArr);
                [[NSUserDefaults standardUserDefaults] setObject:masterKeysArr forKey:MASTER_KEY_ARRAY];
                [[NSUserDefaults standardUserDefaults] setObject:childKeysArr forKey:SUBMIT_KEY_ARRAY];
            }else{
                [[NSUserDefaults standardUserDefaults] setObject:nil forKey:MASTER_KEY_ARRAY];
                [[NSUserDefaults standardUserDefaults] setObject:nil forKey:SUBMIT_KEY_ARRAY];
            }
        }
    } errorHandler:^(NSString *error) {
    }];
} +(void)alertView:(Alert *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSLog(@"buttonIndex:%zd",buttonIndex);
    if (buttonIndex == 1) {
        NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/cn/app/kisslock/id1130667773?mt=8"];
//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; // 弃用，用👇的代替
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str] options:@{} completionHandler:nil]; // iOS 10 之后可用
        
    }
} +(void)requestLockList:(UIActivityIndicatorView *)activityIndicator{
    [self requestLockListWith:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] completionHandler:^(NSDictionary *responseDic) {
        NSLog(@"锁列表返回信息:%@",responseDic);
//        NSString *isSuccess = [responseDic objectForKey:@"success"];
//        if(isSuccess.integerValue == 1){
//            NSDictionary *infor = [responseDic objectForKey:@"infor"];
//            NSArray *lock_grant = [infor objectForKey:@"lock_grant"];
//            
//            if(![lock_grant isKindOfClass:[NSNull class]]){
//                NSArray *secondArr = [NSArray arrayWithArray:lock_grant];
//                for (NSArray *arr in secondArr) {
//                    if(arr.count != 0){
//                        NSDictionary *dic = arr[0];
//                        [self memoryPublicKeys:[dic objectForKey:@"uname"] value:[dic objectForKey:@"code"]];
//                    }
//                }
//            }
//        }
        [activityIndicator stopAnimating];
    } errorHandler:^(NSString *error) {
        [activityIndicator stopAnimating];
    }];
}
#pragma mark - 公钥存储本地
+(void)memoryPublicKeys:(NSString *)key value:(NSString *)value{
    NSString *jsonStr = [SSKeychain passwordForService:@"com.kisslock.guoyang" account:@"publickeysdic"];
    NSDictionary *keysDic = [KLHelp dictionaryWithJsonString:jsonStr];
    NSMutableDictionary *publickeysdic;
    if(keysDic == nil){
        publickeysdic = [NSMutableDictionary dictionary];
    }else{
        publickeysdic = [NSMutableDictionary dictionaryWithDictionary:keysDic];
    }
    [publickeysdic setObject:value forKey:key];
    [SSKeychain setPassword:[KLHelp dictionaryToJson:publickeysdic] forService:@"com.kisslock.guoyang" account:@"publickeysdic"];
}

//注册
+(void)requestRegisterResultWithUserName:(NSString *)userName
                                password:(NSString *)password
                             phoneNumber:(NSString *)phoneNumber
                              temp_token:(NSString *)temp_token
                           completionHandler:(void (^)(NSString *responseString))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_CLIENT_ADD];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:userName forKey:@"username"];
    [dic setObject:password forKey:@"password"];
    [dic setObject:phoneNumber forKey:@"phone"];
    [dic setObject:temp_token forKey:@"temp_token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {

        if (completionHandler != nil) {
            completionHandler([operation responseString]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

// 找回密码
+ (void)findBackPasswordWithKeyType:(NSString *)keyType
                            new_password:(NSString *)newPassword
                              temp_token:(NSString *)temp_token
                       completionHandler:(void (^)(NSString *responseString))completionHandler
                            errorHandler:(void (^)(NSString *error))errorHandler{

    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_PASSWORD_RESET];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:keyType forKey:@"keytype"];
    [dic setObject:newPassword forKey:@"new_password"];
    [dic setObject:temp_token forKey:@"temp_token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    NSLog(@"op.url:%@",op.url);
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler([operation responseString]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//申请验证码
+ (void)requestSecurityCodeWithUserName:(NSString *)userName
                                   type:(NSString *)type
                      completionHandler:(void (^)(NSString *responseString))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_CODE_GET];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:userName forKey:@"mobile"];
    [dic setObject:type forKey:@"type"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler([operation responseString]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//验证随机码服务
+ (void)requestCheckSecurityCodeWithUserName:(NSString *)userName
                                securityCode:(NSString *)code
                      completionHandler:(void (^)(NSString *responseString))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_CODE_VERIFY];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:userName forKey:@"username"];
    [dic setObject:code forKey:@"code"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler([operation responseString]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}


//提交个人信息
+ (void)submitUserInformationWithUserDic:(NSDictionary *)userInforDic
                       completionHandler:(void (^)(NSString *responseString))completionHandler
                            errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_CLIENT_SAVE];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:userInforDic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler([operation responseString]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取个人信息
+ (void)requestUserInformationWithToken:(NSString *)token
                                 userID:(NSString *)userID
                            completionHandler:(void (^)(NSString *responseString))completionHandler
                                 errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_CLIENT_GET];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:token forKey:@"token"];
    [dic setObject:userID forKey:@"id"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler([operation responseString]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//上传图片
+ (void)submitImageDataWithToken:(NSString *)token
                              imageData:(NSData *)imageData
                                keyType:(NSString *)keyType
                      completionHandler:(void (^)(NSString *responseString))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_FILE_UPLOAD];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    NSLog(@"提交了图片");
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:token forKey:@"token"];
    [dic setObject:keyType forKey:@"keytype"];
    [dic setObject:@"0" forKey:@"keyid"];
    [dic setObject:@"0" forKey:@"duration"];
    if(keyType.integerValue == 3){
        [dic setObject:@"1" forKey:@"orderby"];
    }else{
        [dic setObject:@"0" forKey:@"orderby"];
    }
    [dic setObject:@"无" forKey:@"content"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    

    [op addData:imageData forKey:@"temp_file" mimeType:@"application/x-jpg" fileName:@"image.jpg"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler([operation responseString]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//更换手机号
+ (void)requestChangeMobileWithToken:(NSString *)token newPhoneNumber:(NSString *)phoneNumber
                   completionHandler:(void (^)(NSString *responseString))completionHandler
                        errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_CHANAGE_PHONENUMBER];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:token forKey:@"token"];
    [dic setObject:phoneNumber forKey:@"mobile"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler([operation responseString]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//修改密码
+ (void)requestChangePasswordToken:(NSString *)token
                             keytype:(NSString *)keytype
                         oldPassword:(NSString *)old_password
                         newPassword:(NSString *)new_password
                   completionHandler:(void (^)(NSString *responseString))completionHandler
                        errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_PASSWORD_SAVE];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:token forKey:@"token"];
    [dic setObject:keytype forKey:@"keytype"];
    [dic setObject:old_password forKey:@"old_password"];
    [dic setObject:new_password forKey:@"new_password"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler([operation responseString]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//扫描二维码添加锁及锁主钥匙
+ (void)requestAddLockWithLockName:(NSString *)lockName
                         lockUname:(NSString *)lockUname
                              code:(NSString *)code
                 completionHandler:(void (^)(NSString *responseString))completionHandler
                      errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_LOCK_ADD];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:lockName forKey:@"name"];
    [dic setObject:lockUname forKey:@"uname"];
    [dic setObject:code forKey:@"code"];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler([operation responseString]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//添加子钥匙
+ (void)requestAddChildKeyWithLock_id:(NSString *)lock_id
                             mobiel:(NSString *)mobiel
                              keyType:(NSString *)type
                            startdate:(NSString *)startdate
                              enddate:(NSString *)enddate
                                 days:(NSString *)days
                             totalfee:(NSString *)totalfee
                              content:(NSString *)content
                          dataPackage:(NSString *)key_str
                                token:(NSString *)token
                    completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                         errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_KEY_ADD];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:lock_id forKey:@"lock_id"];
    [dic setObject:mobiel forKey:@"mobiel"];
    [dic setObject:type forKey:@"type"];
    [dic setObject:startdate forKey:@"startdate"];
    [dic setObject:enddate forKey:@"enddate"];
    [dic setObject:days forKey:@"days"];
    [dic setObject:totalfee forKey:@"totalfee"];
    [dic setObject:content forKey:@"content"];
    [dic setObject:key_str forKey:@"key_str"];
    [dic setObject:token forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取锁列表
+ (void) requestLockListWith:(NSString *)token
           completionHandler:(void (^)(NSDictionary *responseDic))completionHandler
                errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_LOCK_LIST];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:token forKey:@"token"];
    [dic setObject:@"1" forKey:@"keytype"];
    [dic setObject:@"0" forKey:@"keyid"];
    
    [dic setObject:@"0" forKey:@"page"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
//        NSLog(@"获取的锁列表为:%@",operation.responseString);
        if (completionHandler != nil) {
            completionHandler([operation responseJSON]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取钥匙列表
+ (void) requestKeyListWith:(NSString *)token
           completionHandler:(void (^)(NSDictionary *responseDic))completionHandler
                errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_KEY_LIST];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:token forKey:@"token"];
    [dic setObject:@"2" forKey:@"keytype"];
    [dic setObject:@"0" forKey:@"keyid"];
    NSLog(@"获取钥匙列表的参数;%@",dic);
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        NSLog(@"获取的钥匙列表为:%@",operation.responseString);
        if (completionHandler != nil) {
            completionHandler([operation responseJSON]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//给服务器上传锁返回信息
+ (void)uploadLockBackInfoToServer:(NSMutableArray *)openlockinfor
                 completionHandler:(void (^)(NSDictionary *responseDic))completionHandler
                      errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_RECORD_MYLOCK_SERVICE];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:openlockinfor options:NSJSONWritingPrettyPrinted error:&error];
    //此处data参数是我上面提到的key为"data"的数组
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    [dic setObject:jsonString forKey:@"openlockinfor"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        
        if (completionHandler != nil) {
            completionHandler([operation responseJSON]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//修改锁别名
+ (void)convertLockUnameToNameWithLockID:(NSString *)lock_id
                                   alias:(NSString *)second_name
                       completionHandler:(void (^)(NSDictionary *responseDic))completionHandler
                            errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_UPDATE_LOCK_NAME];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:lock_id forKey:@"lock_id"];
    [dic setObject:second_name forKey:@"second_name"];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler([operation responseJSON]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//修改子钥匙别名
+ (void) reviseChildKeyNameWithKeyID:(NSString *)key_id
                               alias:(NSString *)second_name
                   completionHandler:(void (^)(NSDictionary *responseDic))completionHandler
                        errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_UPDATE_KEY_NAME];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:key_id forKey:@"key_id"];
    [dic setObject:second_name forKey:@"second_name"];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        NSLog(@"修改子钥匙别名返回数据:%@",operation.responseString);
        if (completionHandler != nil) {
            completionHandler([operation responseJSON]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//修改锁地址
+ (void) editLockAddressWithLockID:(NSString *)lock_id
                           address:(NSString *)address
                 completionHandler:(void (^)(NSDictionary *responseDic))completionHandler
                      errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_EDIT_ADDRESS];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:lock_id forKey:@"lock_id"];
    [dic setObject:address forKey:@"address"];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        NSLog(@"修改锁地址返回数据:%@",operation.responseString);
        if (completionHandler != nil) {
            completionHandler([operation responseJSON]);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取子钥匙价格
+ (void)requestGetChild_KeyPriceWithStartDate:(NSString *)startdate
                                    endDate:(NSString *)enddate
                          completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                               errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_GET_KEY_PRICE];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:startdate forKey:@"startdate"];
    [dic setObject:enddate forKey:@"enddate"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取委托价格
+ (void) requestGetGrant_lock_priceWithCompletionHandler:(void (^)(MKNetworkOperation *operation))      completionHandler
                                            errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_GRANT_LOCK_PRICE];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];

}

//分发子钥匙
+ (void) distributeChild_keyWithLockID:(NSString *)lock_id
                                mobile:(NSString *)mobile
                             startdate:(NSString *)startdate
                               enddate:(NSString *)enddate
                              totalfee:(NSString *)totalfee
                              rsa_data:(NSString *)rsa_data
                                 style:(NSString *)style
                           from_key_id:(NSString *)from_key_id
                                AESkey:(NSString *)AESkey
                                 power:(NSString *)power
                            updatetime:(NSString *)updatetime
                                 token:(NSString *)token
                           commondCode:(NSString *)Command_code
                     completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                          errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_KEY_ADD];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:lock_id forKey:@"lock_id"];
    [dic setObject:mobile forKey:@"mobile"];
    [dic setObject:startdate forKey:@"startdate"];
    [dic setObject:enddate forKey:@"enddate"];
    [dic setObject:totalfee forKey:@"totalfee"];
    [dic setObject:rsa_data forKey:@"rsa_data"];
    [dic setObject:style forKey:@"style"];
    [dic setObject:from_key_id forKey:@"from_key_id"];
    [dic setObject:AESkey forKey:@"AESkey"];
    [dic setObject:power forKey:@"power"];
    [dic setObject:updatetime forKey:@"updatetime"];
    [dic setObject:token forKey:@"token"];
    [dic setObject:Command_code forKey:@"Command_code"];
    
    //本机当前时间(用于自定义单号)
    NSDate *  senddate=[NSDate date];
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYYMMddHHmmss"];
    NSString *locationString=[dateformatter stringFromDate:senddate];
    NSString *trade_no = [NSString stringWithFormat:@"%@%@%@",locationString,[[NSUserDefaults standardUserDefaults] objectForKey:@"phoneNumber"],totalfee];
    [dic setObject:trade_no forKey:@"trade_no"];
    
    NSLog(@"钥匙发送参数;%@",dic);
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        NSLog(@"分发单个子钥匙的返回结果:%@",operation.responseString);
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//删除子钥匙
+ (void) removeOutOfDateChildKeyWithToken:(NSString *)token
                                   key_id:(NSString *)key_id
                        completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                             errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_KEY_REMOVE];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:key_id forKey:@"id"];
    [dic setObject:token forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//删除所有临时钥匙
+ (void) removeAllTemporaryKeyWithToken:(NSString *)token
                                lock_id:(NSString *)lock_id
                      completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_SERINUMBER_INCREASE];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:lock_id forKey:@"lock_id"];
    [dic setObject:token forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//发送委托管理命令
+ (void) sendDelegateCommondWithLock_id:(NSString *)lock_id
                                 mobile:(NSString *)mobile
                        command_content:(NSString *)command_content
                                   type:(NSString *)type
                                apptime:(NSString *)apptime
                           commond_data:(NSString *)command_data
                               totalfee:(NSString *)totalfee
                      completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_RECEIVE_COMMAND];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:lock_id forKey:@"lock_id"];
    [dic setObject:mobile forKey:@"mobile"];
    [dic setObject:command_content forKey:@"command_content"];
    [dic setObject:type forKey:@"type"];
    [dic setObject:apptime forKey:@"apptime"];
    [dic setObject:totalfee forKey:@"totalfee"];
    NSLog(@"委托参数:%@",command_data);
    [dic setObject:command_data forKey:@"command_data"];
    
    if([type isEqualToString:@"3"]){
        [dic setObject:@"2" forKey:@"keytype"];
        [dic setObject:[HemaFunction getStringNow] forKey:@"trade_no"];
    }
    NSLog(@"dic:%@",dic);
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取所有的委托命令
+ (void) getCommondListWithToken:(NSString *)token
               completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                    errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_GET_COMMOND_LIST];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:token forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//执行委托命令成功返回服务器
+ (void) implementCommondSuccessWithCommondId:(NSString *)command_id
                            completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                 errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_UPDATE_STATUS];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:command_id forKey:@"command_id"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//发送钥匙串
+ (void) sendKeysGroupWithLockArray:(NSMutableArray *)lockArray
                            keytype:(NSString *)keytype
                           trade_no:(NSString *)trade_no
                           totalfee:(NSString *)totalfee
                  completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                       errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_KEYSTRING_ADD];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:keytype forKey:@"keytype"];
    [dic setObject:trade_no forKey:@"trade_no"];
    [dic setObject:totalfee forKey:@"totalfee"];
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:lockArray options:NSJSONWritingPrettyPrinted error:&error];
    //此处data参数是我上面提到的key为"data"的数组
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    [dic setObject:jsonString forKey:@"keystring_infor"];
    
    NSLog(@"dic:%@",dic);
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        NSLog(@"发钥匙串返回数据:%@",operation.responseString);
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//充值或支付成功
+ (void) payoffSuccessWithKeytype:(NSString *)keytype
                        total_fee:(NSString *)totalfee
                         trade_no:(NSString *)tradeNo
                completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                     errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_RECHARGE];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:keytype forKey:@"keytype"];
    [dic setObject:totalfee forKey:@"totalfee"];
    [dic setObject:tradeNo forKey:@"trade_no"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//提现申请
+ (void) cashRequestWithApplyfee:(NSString *)applyfee
                     paypassword:(NSString *)paypassword
                         keytype:(NSString *)keytype
               completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                    errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_CASH_ADD];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:keytype forKey:@"keytype"];
    [dic setObject:paypassword forKey:@"paypassword"];
    [dic setObject:applyfee forKey:@"applyfee"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//用户支付宝保存
+ (void) saveUsersAliAccountWithAliuser:(NSString *)aliuser
                     aliNickName:(NSString *)nickname
               completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                    errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_ALI_SAVE];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:nickname forKey:@"ali_nickname"];
    [dic setObject:aliuser forKey:@"aliuser"];
    NSLog(@"支付宝保存信息：%@",dic);
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//设置支付密码
+ (void) setPayPasswordWithPassword:(NSString *)paypassword
                  completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                       errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_PAYPASSWORD_SAVE];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:paypassword forKey:@"paypassword"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//检测是否设置了支付密码 is_exist_paypassword
+ (void) checkIsExitPaypwdCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                               errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_ISEXIT_PAYPASSWORD];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取金额明细
+ (void) requestAccounListWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                   errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_ACCOUNT_LIST];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取余额
+ (void) requestBalanceWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_GET_BALANCE];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取开锁记录
+ (void) requestOpenLockHistroryWithLockID:(NSString *)lock_id
                                  page_num:(NSString *)page_num
                         completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                              errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_OPENLOCK_HISTORY];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:lock_id forKey:@"lock_id"];
    [dic setObject:page_num forKey:@"page_num"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取二级锁主列表
+ (void) requestSecondUserListWithLock_ID:(NSString *)lock_id
                        completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                            errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_GRANT_LOCK];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:lock_id forKey:@"lock_id"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取二级锁主下的子钥匙列表
+ (void) requestSecondChildKeyWithSecondID:(NSString *)client_id
                                   lock_id:(NSString *)lock_id
                         completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                              errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_KEY_GRANT];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:client_id forKey:@"client_id"];
    [dic setObject:lock_id forKey:@"lock_id"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取历史发送钥匙的手机号
+ (void) requestHistorySendKeysPhoneListWithClientID:(NSString *)client_id
                           completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_PHONE_LIST];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:client_id forKey:@"client_id"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//是否公开锁主被申请权限
+ (void) isTheLockAllowdToBeApplyWithStatus:(NSString *)status
                                     lockID:(NSString *)lock_id
                          completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                               errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_LOCK_STATUS];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:status forKey:@"status"];
    [dic setObject:lock_id forKey:@"lock_id"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取可被申请的锁/钥匙串列表
+ (void) requestAllowedToBeApplyLockListWIthMoblie:(NSString *)moblie
                                 completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                      errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_MAY_APPLY_LOCK];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:moblie forKey:@"mobile"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//发送申请钥匙请求
+ (void) requestApplyForKeysWithMoblie:(NSString *)moblie
                                 prict:(NSString *)price
                             startDate:(NSString *)startdate
                               endDate:(NSString *)endDate
                                lockid:(NSArray *)lock_id
                               message:(NSString *)message
                                  type:(NSString *)type
                     completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                          errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_APPLICATION_KEY];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
//    NSError *error;
//    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:lock_id options:NSJSONWritingPrettyPrinted error:&error];//此处data参数是我上面提到的key为"data"的数组
//    NSString *lockString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:moblie forKey:@"mobile"];
    [dic setObject:price forKey:@"price"];
    [dic setObject:startdate forKey:@"startdate"];
    [dic setObject:endDate forKey:@"enddate"];
    [dic setObject:[lock_id lastObject] forKey:@"lockid_or_keychainid"];
    [dic setObject:message forKey:@"message"];
    [dic setObject:type forKey:@"type"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取已经发送的申请记录
+ (void) requestHaveApplyedForKeyListWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                              errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_APPLICANTS_ID_MESSAGE];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];

    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取申请钥匙消息列表
+ (void) requestApplyKeyMessageWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                        errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_LOCK_APPLY_MESSAGE];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
  
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//是否同意申请／撤销申请请求 'rsa_data','AESkey', 'news_id', 'power', 'Command_code','updatetime' 'status'
+ (void) requestMasterIsAgreedWithKey_str:(NSString *)rsa_data
                                   AESkey:(NSString *)AESkey
                                    power:(NSString *)power
                             Command_code:(NSString *)Command_code
                               updatetime:(NSString *)updatetime
                                  news_id:(NSString *)news_id
                                   status:(NSString *)status
                        completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                             errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_APPLICATION_PASS];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:rsa_data forKey:@"rsa_data"];
    [dic setObject:AESkey forKey:@"AESkey"];
    [dic setObject:power forKey:@"power"];
    [dic setObject:Command_code forKey:@"Command_code"];
    [dic setObject:updatetime forKey:@"updatetime"];
    [dic setObject:news_id forKey:@"news_id"];
    [dic setObject:status forKey:@"status"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//删除申请钥匙纪录
+(void) requestRemoveApplyKeyHidtoryWithNews_id:(NSString *)news_id
                              completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                   errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_DELETE_APPLICATION];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:news_id forKey:@"news_id"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//放弃锁主权限
+(void) requestGiveUpMasterPowerWithLockID:(NSString *)lock_id
                         completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                              errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_GIVE_UP_LOCKRIGHT];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:lock_id forKey:@"lock_id"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//是否有新的版本
+(void) requestIsHaveNewVesionWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                       errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_CHECK_VESION];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:devicetype forKey:@"devicetype"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//删除钥匙后更新所有临时钥匙
+(void) requestUpdataAllTemporaryKeysWithPackageArr:(NSArray *)childPackages
                                  completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                       errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_UPDATE_KEYS];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:childPackages options:NSJSONWritingPrettyPrinted error:&error];//此处data参数是我上面提到的key为"data"的数组
    NSString *keychain = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:keychain forKey:@"keychain"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//创建钥匙串
+(void) requestKeyBrunchWithGroupName:(NSString *)group_name
                            lock_list:(NSArray *)lock_list
                    completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                         errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_GET_NEW_GROUP];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:lock_list options:NSJSONWritingPrettyPrinted error:&error];//此处data参数是我上面提到的key为"data"的数组
    NSString *locklist = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:group_name forKey:@"group_name"];
    [dic setObject:locklist forKey:@"locklist"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取所有创建/发出的钥匙串
+(void) requestGetAllKeyBrunchWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                       errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_GET_GROUPLIST_SEND];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//是否允许其他人申请该钥匙串
+(void) requestAllowedKeysBrunchApplyedWithFrom_id:(NSString *)from_id
                                              type:(NSString *)type
                                            status:(NSString *)status
                                 completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                      errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_UPDATE_GROUP_STATUS];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:from_id forKey:@"from_id"];
    [dic setObject:type forKey:@"type"];
    [dic setObject:status forKey:@"status"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取该组内的所有锁
+(void) requestAllLocksOfBrunchWithID:(NSString *)ID
                                 type:(NSString *)type
                          completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                               errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_GET_GROUP_LOCKLIST];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:ID forKey:@"id"];
    [dic setObject:type forKey:@"type"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//编辑该组内的锁
+(void) requestEditCurrentBrunchWithGroup_id:(NSString *)group_id
                           completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_GET_EDITGROUP_LOCKLIST];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:group_id forKey:@"group_id"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//保存该组内的锁
+(void) requestSaveCurrentBrunchWithGroup_id:(NSString *)group_id
                                    lockList:(NSMutableArray *)locklist
                           completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_SAVE_EDIT_GROUP];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:locklist options:NSJSONWritingPrettyPrinted error:&error];//此处data参数是我上面提到的key为"data"的数组
    NSString *locklistStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:group_id forKey:@"group_id"];
    [dic setObject:locklistStr forKey:@"locklist"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//发送钥匙串（新）
+(void) new_requestSendLockGroupWithStyle:(NSString *)style
                                    power:(NSString *)power
                                lockinfor:(NSMutableArray *)lockinfor
                             Command_code:(NSString *)Command_code
                                 group_id:(NSString *)group_id
                                   mobile:(NSString *)mobile
                                  enddate:(NSString *)enddate
                                startdate:(NSString *)startdate
                               updatetime:(NSString *)updatetime
                                 totalfee:(NSString *)totalfee
                                  from_id:(NSString *)from_id
                                authorize:(NSString *)authorize
                        completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                             errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/send_lock_group/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];

    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:style forKey:@"style"];
    [dic setObject:power forKey:@"power"];
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:lockinfor options:NSJSONWritingPrettyPrinted error:&error];//此处data参数是我上面提到的key为"data"的数组
    NSString *lockinfoStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    [dic setObject:lockinfoStr forKey:@"lockinfor"];
    [dic setObject:Command_code forKey:@"Command_code"];
    [dic setObject:group_id forKey:@"group_id"];
    [dic setObject:mobile forKey:@"mobile"];
    [dic setObject:enddate forKey:@"enddate"];
    [dic setObject:startdate forKey:@"startdate"];
    [dic setObject:updatetime forKey:@"updatetime"];
    [dic setObject:totalfee forKey:@"totalfee"];
    [dic setObject:from_id forKey:@"from_id"];
    [dic setObject:authorize forKey:@"authorize"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取钥匙串的费用
+(void) getKeyGroupTotalFeeWithStartDate:(NSString *)startdate
                                 endDate:(NSString *)enddate
                                   style:(NSString *)style
                               authorize:(NSString *)authorize
                                group_id:(NSString *)group_id
                                   power:(NSString *)power
                       completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                            errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/getkeychainprice_newversions/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:startdate forKey:@"startdate"];
    [dic setObject:enddate forKey:@"enddate"];
    [dic setObject:style forKey:@"style"];
    [dic setObject:authorize forKey:@"authorize"];
    [dic setObject:group_id forKey:@"group_id"];
    [dic setObject:power forKey:@"power"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}
//获取收到的钥匙串列表
+(void) getReceiveGroupBrunchListWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                       errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/get_grouplist_receive/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取创建的/收到的钥匙串
+(void) getCreatAndReceivedGroupListWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                             errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/customized_grouplist/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//修改钥匙串名称
+(void) editGroupBrunchNameWithGroup_id:(NSString *)group_id
                                   type:(NSString *)type
                             group_name:(NSString *)group_name
                      completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/update_group_name/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:group_id forKey:@"group_id"];
    [dic setObject:type forKey:@"type"];//type=1修改创建组的名称，type=2修改转发组的名称
    [dic setObject:group_name forKey:@"group_name"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取子钥匙的价格
+(void) getNewSendKeyTotalfeeWithStartdate:(NSString *)startdate
                                   enddate:(NSString *)enddate
                         completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                              errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/getkeyprice_newversion/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:startdate forKey:@"startdate"];
    [dic setObject:enddate forKey:@"enddate"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//向锁发送委托命令
+(void) sendCommondToLockWithLock_id:(NSString *)lock_id
                              mobile:(NSString *)mobile
                                 rsa:(NSString *)rsa
                              AESkey:(NSString *)AESkey
                                type:(NSString *)type
                             apptime:(NSString *)apptime
                        command_code:(NSString *)command_code
                           begintime:(NSString *)begintime
                             endtime:(NSString *)endtime
                               style:(NSString *)style
                          set_mobile:(NSString *)set_mobile
                   completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                        errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/sent_command/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:lock_id forKey:@"lock_id"];
    [dic setObject:mobile forKey:@"mobile"];
    [dic setObject:rsa forKey:@"rsa"];
    [dic setObject:AESkey forKey:@"AESkey"];
    [dic setObject:type forKey:@"type"];
    [dic setObject:apptime forKey:@"apptime"];
    [dic setObject:command_code forKey:@"command_code"];
    [dic setObject:begintime forKey:@"begintime"];
    [dic setObject:endtime forKey:@"endtime"];
    [dic setObject:style forKey:@"style"];
    [dic setObject:set_mobile forKey:@"set_mobile"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//删除一把钥匙
+(void) delegateOneKeyWithKeyID:(NSString *)key_id
                           type:(NSString *)type
              completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                   errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/delete_one_key/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:key_id forKey:@"key_id"];
    [dic setObject:type forKey:@"type"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//取消一个用户的二级锁主权限
+(void) cancelOneSeconMasterPowerWithLock_id:(NSString *)lock_id
                                      mobile:(NSString *)mobile
                                        type:(NSString *)type
                    completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                         errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/give_up_seclock/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:lock_id forKey:@"lock_id"];
    [dic setObject:mobile forKey:@"mobile"];
    [dic setObject:type forKey:@"type"];
    
    NSLog(@"dic:%@",dic);
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//数据同步
+(void) dataSynchronizationWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                    errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/update_app_data_newversion/";
//    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/update_data/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];

    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//删除钥匙串转发组
+(void) deleteAllLockBrunchWithGroup_transfer_id:(NSString *)group_transfer_id
                                            type:(NSString *)type
                               completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                    errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/delete_transfer_group/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:group_transfer_id forKey:@"group_transfer_id"];
    [dic setObject:type forKey:@"type"];//0不删除子节点，1删除子节点
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//删除模板钥匙串
+(void) deleteUserDefineBrunchWithBrunch_id:(NSString *)brunch_id
                          completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                               errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/delete_lock_group/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:brunch_id forKey:@"id"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//同意一级/二级钥匙串的申请 RSA_AES','AESkey', 'news_id', 'power', 'Command_code','updatetime'
+(void) agreeTheKeyBrunchApplyedWithLockInfo:(NSMutableArray *)lockinfor
                                     news_id:(NSString *)news_id
                                       power:(NSString *)power
                                Command_code:(NSString *)Command_code
                                  updatetime:(NSString *)updatetime
                                      status:(NSString *)status
                           completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = [NSString stringWithFormat:@"/hm_kisslockcloud/index.php/Webservice/V100/%@/",REQUEST_APPLICATION_KEY];
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSError *error;
    NSData *jsonDataLockInfor = [NSJSONSerialization dataWithJSONObject:lockinfor options:NSJSONWritingPrettyPrinted error:&error];//此处data参数是我上面提到的key为"data"的数组
    NSString *lockInforString = [[NSString alloc] initWithData:jsonDataLockInfor encoding:NSUTF8StringEncoding];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:news_id forKey:@"news_id"];
    [dic setObject:power forKey:@"power"];
    [dic setObject:Command_code forKey:@"Command_code"];
    [dic setObject:updatetime forKey:@"updatetime"];
    [dic setObject:lockInforString forKey:@"lockinfor"];
    [dic setObject:status forKey:@"status"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//获取所有委托命令列表
+(void) getAllCommandHistoryWithLock_id:(NSString *)lock_id
                      completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/get_allcommand_list_newversion/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:lock_id forKey:@"lock_id"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//将手机号转化为用户id
+(void) phoneNumberChangeToUserIDWithPhoneNUm:(NSString *)phoneNumber
                            completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                 errorHandler:(void (^)(NSString *error))errorHandler{
    NSString *path = @"/hm_kisslockcloud/index.php/Webservice/V100/get_userid/";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"] forKey:@"token"];
    [dic setObject:phoneNumber forKey:@"mobile"];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:dic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        if (completionHandler != nil) {
            completionHandler(operation);
        }
    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
        if (errorHandler != nil) {
            errorHandler([err localizedDescription]);
        }
    }];
    
    [engine enqueueOperation:op];
}

//*********************** 2.0 新加 ********************
#pragma mark 2.0 新增加
+ (void)mkPOSTWithPath:(NSString *)path params:(NSDictionary *)parDic CompleteHandler:(void (^)(MKNetworkOperation *))completeHandler errorHandler:(void (^)(NSString *))errorHandler {
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:parDic httpMethod:@"POST"];
    
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        completeHandler(completedOperation);
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        errorHandler([error localizedDescription]);
    }];
    
    [engine enqueueOperation:op];
}

/**设置手势密码*/
+ (void)setupGesturePassword:(NSString *)gesturePwd successBlock:(void (^)(MKNetworkOperation *operation))success failureBlock:(void (^)(NSString *err))failure {


    NSString *path = @"/hm_kisslockcloud/index.php/webservice/V200/set_gesturepassword/";
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    [params setObject:token forKey:@"token"];
    [params setObject:gesturePwd forKey:@"gesturepassword"];
    
    [self mkPOSTWithPath:path params:params CompleteHandler:^(MKNetworkOperation *operation) {
        success(operation);
    } errorHandler:^(NSString *error) {
        failure(error);
    }];
}

/**修改手势密码*/
+ (void)modifyGesturePasswordWithOldPwd:(NSString *)old_pwd new_pwd:(NSString *)new_pwd successBlock:(void (^)(MKNetworkOperation *operation))success failureBlock:(void (^)(NSString *err))failure {
    NSString *path = @"/hm_kisslockcloud/index.php/webservice/V200/update_gesturepassword/";

    NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:old_pwd forKey:@"old_password"];
    [params setObject:new_pwd forKey:@"old_password"];
    [params setObject:token forKey:@"token"];
    
    [self mkPOSTWithPath:path params:params CompleteHandler:^(MKNetworkOperation *operation) {
        NSLog(@"修改手势密码:%@",operation);
        success(operation);
        
    } errorHandler:^(NSString *error) {
        NSLog(@"%@",error);
        failure(error);
    }];
}

/**3. 重置手势密码时,先验证登陆密码*/
+ (void)checkLoginpwdWhenResetGesturePasswordWithLoginpwd:(NSString *)loginpwd verifyCode:(NSString *)verifyCode completeHandler:(void (^)(MKNetworkOperation * operation))compleHandler errorHandler:(void (^)(NSString *err))errorHandler {
    NSString *path = @"/hm_kisslockcloud/index.php/webservice/V200/check_login_password/";
    
    NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    [parDic setObject:loginpwd forKey:@"login_password"];
    [parDic setObject:verifyCode forKey:@"code"];
    [parDic setObject:token forKey:@"token"];
    
    MKNetworkEngine *engin = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    MKNetworkOperation *op = [engin operationWithPath:path params:parDic httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        
        compleHandler(completedOperation);
        
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        errorHandler([error localizedDescription]);
    }];
    
    [engin enqueueOperation:op];
}

/**4.重置手势密码*/
+ (void)resetGesturePasswordWithNewpwd:(NSString *)new_password
                     completionHandler:(void(^)(MKNetworkOperation *operation))completeHandler
                          errorHandler:(void(^)(NSString *error))errorHandler {
    NSString *path = @"/hm_kisslockcloud/index.php/webservice/V200/reset_gesturepassword/";
    
    NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    [parDic setObject:new_password forKey:@"new_password"];
    [parDic setObject:token forKey:@"token"];
    
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS customHeaderFields:nil];
    
    MKNetworkOperation *op = [engine operationWithPath:path params:parDic httpMethod:@"POST"] ;
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
       
        completeHandler(completedOperation);
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        errorHandler([error localizedDescription]);
    }];
    
    [engine enqueueOperation:op];
    
}

/**5.验证手势密码*/
+ (void)verifyGesturePasswordWithPwd:(NSString *)pwd successBlock:(void(^)(id responObjc))success failureBlock:(void(^)(NSError *error))failure{
    //1.path
    NSString *path = [NSString stringWithFormat:@"%@%@/",MainPath,REQUEST_check_gesturepassword];
    
    //2.参数
    NSMutableDictionary *parmDic = [NSMutableDictionary dictionary];
    NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey: @"token"];
    [parmDic setObject:pwd forKey:@"password"];
    [parmDic setObject:token forKey:@"token"];
    
    //3.引擎
    MKNetworkEngine *engin = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS];
    
    //4.操作对象
    MKNetworkOperation *op = [engin operationWithPath:path params:parmDic httpMethod:@"POST"];
    
    //5.请求 回调
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        success(completedOperation.responseString);
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        failure(error);
    }];
    
    //6.添加到引擎
    [engin enqueueOperation:op];
}


/**6.获取免密操作列表*/
+ (void)mianmiListGesturePasswordSuccessBlock:(void (^)(id resObjc))success failureBlock:(void (^)(NSError *err))failure {
    //1. 路径
    NSString *path = [NSString stringWithFormat:@"%@%@/",MainPath,REQUEST_get_updated_operations];
    
    //2. 参数
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    if (token.length) {
        [parDic setObject:token forKey:@"token"];
    }else {
        [parDic setObject:@"" forKey:@"token"];
    }
    
    //3. 创建引擎
    MKNetworkEngine *engin = [[MKNetworkEngine alloc] initWithHostName:HTTP_SERVER_ADDRESS];
    
    //4. 创建操作
    MKNetworkOperation *op = [engin operationWithPath:path params:parDic httpMethod:@"POST"];
    
    //5. 请求回调
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        success(completedOperation.responseString);
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        failure(error);
    }];
    
    //6. 添加到引擎
    [engin enqueueOperation:op];
}



@end
